﻿#include "TreeWidgetPropertyEditEntry.h"
#include <QTreeWidget>

#include "IntegerEditEntry.h"

#include "ObjectPropertyEditEntryFactory.h"
REGISTER_PROPERTY_EDIT_ENTRY(TreeWidget)

struct TreeWidgetPropertyEditEntry::TreeWidgetPropertyEditEntryPrivate {
    QPointer<QTreeWidget> treeWidget;
    QPointer<IntegerEditEntry> entryColumnCount;
};

TreeWidgetPropertyEditEntry::~TreeWidgetPropertyEditEntry() { }

TreeWidgetPropertyEditEntry::TreeWidgetPropertyEditEntry(QWidget *parent) : PropertyEditEntry{parent} {
    p.reset(new TreeWidgetPropertyEditEntryPrivate);
    initUi();
    retranslateUi();
}

TreeWidgetPropertyEditEntry::TreeWidgetPropertyEditEntry(void *object, QWidget *parent) : PropertyEditEntry{parent} {
    p.reset(new TreeWidgetPropertyEditEntryPrivate);
    initUi();
    retranslateUi();
    setObject(object);
}

void TreeWidgetPropertyEditEntry::setObject(void *object) {
    p->treeWidget = static_cast<QTreeWidget*>(object);
}

void TreeWidgetPropertyEditEntry::onTick() {
    if (!p->treeWidget || !isVisible()) {
        return;
    }

    p->entryColumnCount->setValue(p->treeWidget->columnCount());
}

void TreeWidgetPropertyEditEntry::initUi() {
    p->entryColumnCount = new IntegerEditEntry;
    appendChildEntry(p->entryColumnCount);
}

void TreeWidgetPropertyEditEntry::retranslateUi() {
    setTitle(tr("QTreeWidget"));
    p->entryColumnCount->setTitle(tr("columnCount"));

}
